# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=nbviewer
pkgbase=mingw-w64-python-jupyter-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-jupyter-${_realname}
pkgver=1.0.1
pkgrel=3
pkgdesc='Render Jupyter Notebooks as static web pages (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://jupyter.org'
license=('BSD')
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-elasticsearch
    ${MINGW_PACKAGE_PREFIX}-python-ipython
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-nbconvert
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-nbformat
    ${MINGW_PACKAGE_PREFIX}-python-jupyter_client
    ${MINGW_PACKAGE_PREFIX}-python-markdown
    ${MINGW_PACKAGE_PREFIX}-python-pycurl
    ${MINGW_PACKAGE_PREFIX}-python-statsd
)
makedepends=(
    ${MINGW_PACKAGE_PREFIX}-python-setuptools
    ${MINGW_PACKAGE_PREFIX}-python-wheel
    ${MINGW_PACKAGE_PREFIX}-python-invoke
)
source=("${_realname}-${pkgver}.tar.gz::https://github.com/jupyter/${_realname}/archive/${pkgver}.tar.gz")
sha256sums=('2fe0b0ee8ec5c8e2e173b8f15a22e42ba583fc6d4fa60ddb7aa40e9ee972f268')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"

  # Disable check for non-windows modules
  sed -i "s|newrelic!=2.80.0.60||g" requirements.txt
  sed -i "s|pylibmc||g" requirements.txt

  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
